﻿#define _CRT_SECURE_NO_WARNINGS 1
//分治：颜⾊分类（medium）：https://leetcode.cn/problems/sort-colors/description/
class Solution {
public:
    void sortColors(vector<int>& nums) {
        int n = nums.size();
        int left = -1, right = n, i = 0;
        while (i < right)
        {
            if (nums[i] == 0)
            {
                swap(nums[i++], nums[++left]);
            }
            else if (nums[i] == 1)
            {
                i++;
            }
            else
            {
                swap(nums[--right], nums[i]);
            }
        }
    }
};